package com.caine.ts.ch21;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

import com.caine_ts.R;

public class Lesson21 extends Activity {

	private Button btn_1 = null;
	private Button btn_2 = null;
	private Button btn_3 = null;
	private Button btn_4 = null;
	private Button btn_5 = null;
	private Button btn_6 = null;
	private Intent intent = null;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.lesson21);
		init();

	}

	void init() {
		btn_1 = (Button) findViewById(R.id.btn_1);
		btn_2 = (Button) findViewById(R.id.btn_2);
		btn_3 = (Button) findViewById(R.id.btn_3);
		btn_4 = (Button) findViewById(R.id.btn_4);
		btn_5 = (Button) findViewById(R.id.btn_5);
		btn_6 = (Button) findViewById(R.id.btn_6);
		btn_1.setOnClickListener(listener);
		btn_2.setOnClickListener(listener);
		btn_3.setOnClickListener(listener);
		btn_4.setOnClickListener(listener);
		btn_5.setOnClickListener(listener);
		btn_6.setOnClickListener(listener);
		btn_1.setText("go to web!(ACTION_VIEW)");
		btn_2.setText("edit contacts(ACTION_EDIT)");
		btn_3.setText("view contacts(ACTION_DIAL)");
		btn_4.setText("phone call(ACTION_CALL)");
		btn_5.setText("go to web!");
		btn_6.setText("go to web!");
	}

	private OnClickListener listener = new OnClickListener() {

		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			String data = "content://com.android.contacts/contacts/1";
			switch (v.getId()) {
			case R.id.btn_1:
				intent = new Intent();
				intent.setAction(Intent.ACTION_VIEW);
				intent.setData(Uri.parse("http://www.baidu.com"));
				startActivity(intent);
				break;
			case R.id.btn_2:
				intent = new Intent();
				intent.setAction(Intent.ACTION_EDIT);
				intent.setData(Uri.parse(data));
				startActivity(intent);
				break;
			case R.id.btn_3:
				intent = new Intent();
				intent.setAction(Intent.ACTION_DIAL);
				intent.setData(Uri.parse("tel:112"));
				startActivity(intent);
				break;
			case R.id.btn_4:
				intent = new Intent();
				intent.setAction(Intent.ACTION_CALL);
				intent.setData(Uri.parse(data));
				startActivity(intent);
				break;
			case R.id.btn_5:
				intent = new Intent();
				intent.setAction(Intent.ACTION_CAMERA_BUTTON);
				//intent.setData(Uri.parse("http://www.baidu.com"));
				startActivity(intent);
				break;
			case R.id.btn_6:
				intent = new Intent();
				intent.setAction(Intent.ACTION_VIEW);
				intent.setData(Uri.parse("http://www.baidu.com"));
				startActivity(intent);
				break;
			}
		}
	};
}
